<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>axios基本使用</title>
    <link crossorigin="anonymous" href="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/css/bootstrap.min.css"
          rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<div class="container">
    <h2 class="page-header">基本使用</h2>
    <button class="btn btn-primary"> 发送GET请求</button>
    <button class="btn btn-warning"> 发送POST请求</button>
    <button class="btn btn-success"> 发送 PUT 请求</button>
    <button class="btn btn-danger"> 发送 DELETE 请求</button>
</div>
<script>
    // GET
    $(".btn-primary").click(function () {
        axios({
            method: 'GET',
            url: 'http://localhost:3000/posts/3'
        }).then(resp => {
            console.log(resp);
        });
        return false;
    });

    // POST
    $(".btn-warning").click(function () {
        axios({
            method: 'POST',
            url: 'http://localhost:3000/posts/',
            data:{
                title:"佛教的什么发大水佛理",
                author:"张三"
            }
        }).then(resp => {
            console.log(resp);
        });
        return false;
    });

    // PUT
    $(".btn-success").click(function () {
        axios({
            method: 'PUT',
            url: 'http://localhost:3000/posts/3',
            data:{
                title:"佛教的什么发大水佛理",
                author:"李四"
            }
        }).then(resp => {
            console.log(resp);
        });
        return false;
    });

    // DELETE
    $(".btn-danger").click(function () {
        axios({
            method: 'DELETE',
            url: 'http://localhost:3000/posts/4'
        }).then(resp => {
            console.log(resp);
        });
        return false;
    });
</script>
</body>

</html>